<?php

/**
 * 自定义 失败 返回
 *
 * @param int $code
 * @param string $msg
 * @param string $data
 * @throws HttpResponseException
 */
if (!function_exists('fish_fail')) {
    function fish_fail($msg = "error", $data = [], $code = 1000)
    {
        $result = [
            'code' => $code,
            'message' => $msg,
            'data' => $data,
        ];
        $header['Access-Control-Allow-Origin'] = '*';
        $header['Access-Control-Allow-Headers'] = 'X-Requested-With,Content-Type,XX-Device-Type,XX-Token,Authorization,XX-Api-Version,XX-Wxapp-AppId';
        $header['Access-Control-Allow-Methods'] = 'GET,POST,PATCH,PUT,DELETE,OPTIONS';
        $response = response()->json($result);
        $response = $response->withHeaders($header);
        throw new Illuminate\Http\Exceptions\HttpResponseException($response);
    }
}

/**
 * 自定义 成功 返回
 *
 * @param int $code
 * @param string $msg
 * @param string $data
 * @throws HttpResponseException
 */
if (!function_exists('fish_success')) {
    function fish_success($msg = '', $data = [], $code = 200)
    {
        $result = [
            'code' => $code,
            'message' => $msg,
            'data' => $data,
        ];
        $header['Access-Control-Allow-Origin'] = '*';
        $header['Access-Control-Allow-Headers'] = 'X-Requested-With,Content-Type,XX-Device-Type,XX-Token,Authorization,XX-Api-Version,XX-Wxapp-AppId';
        $header['Access-Control-Allow-Methods'] = 'GET,POST,PATCH,PUT,DELETE,OPTIONS';
        $response = response()->json($result);
        $response = $response->withHeaders($header);
        throw new Illuminate\Http\Exceptions\HttpResponseException($response);
    }
}